from django.shortcuts import render
import os
import requests
from bddjango import api_decorator


html_dir = 'templates'


# 返回templates中的login.html文件
def myIframe(request):
    html_file = 'myIframe.html'

    if 0:
        url = 'https://www.douban.com/'
        # html_file = 'test.html'
        html_path = os.path.join(html_dir, html_file)

        r = requests.get(url)  # 豆瓣首页
        with open(html_path, 'w', encoding='utf-8') as f:
            f.write(r.text)

    return render(request, html_file)


def wxAuthFile(request):
    return render(request, '9YKIOhn1Vd.txt')


@api_decorator
def myHtml(request, path):
    global html_dir
    html_file = path
    html_path = os.path.join(html_dir, html_file)
    html_path = os.path.normpath(html_path)
    assert os.path.exists(html_path), f'文件{html_path}不存在!'
    return render(request, html_file)

